package com.cn.springcloudwechat.controller.find.askDoctor;

import com.cn.springcloudwechat.common.ajax.AjaxRes;
import com.cn.springcloudwechat.common.utils.Const;
import com.cn.springcloudwechat.model.YmUser;
import com.cn.springcloudwechat.model.find.askDoctor.YmDoctor;
import com.cn.springcloudwechat.model.find.askDoctor.YmDoctorLevel;
import com.cn.springcloudwechat.model.find.askDoctor.YmDoctorWork;
import com.cn.springcloudwechat.model.find.askDoctor.YmDouctorConsultType;
import com.cn.springcloudwechat.service.find.askDoctor.AskDoctorService;
import com.cn.springcloudwechat.service.find.askDoctor.YmDoctorWorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/*
* 问医生Controller
* */
@Controller
@ResponseBody
@RequestMapping("/askDoctor/")
public class AskDoctorController {
    @Autowired
    AskDoctorService askDoctorService;
    @Autowired
    YmDoctorWorkService ymDoctorWorkService;
    /*
     * 测试接口
     * */
    @RequestMapping("helloword")
    public void helloword(){
        System.err.print("+++++++++++++++++++++++hello word++++++++++++++++++++++");
    }

    /*
     * 查询医生详细信息
     * */
    @RequestMapping("queryDoctorInfo")
    public AjaxRes queryDoctorInfoByUserId(AjaxRes ajaxRes, Long userId){
        try {
            YmDoctor ymDoctor = askDoctorService.queryDoctorInfoByUserId(userId);
            ajaxRes.setSucceed(ymDoctor,Const.DATA_SUCCEED);
        } catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }

    /*
     * 查询医生ID
     * */
    @RequestMapping("queryDoctorId")
    public AjaxRes queryDoctorIdByUserId(AjaxRes ajaxRes, Long userId){
        try {
            YmDoctor ymDoctor = askDoctorService.queryDoctorInfoByUserId(userId);
            Long doctorId = ymDoctor.getDoctorId();
            ajaxRes.setSucceed(doctorId,Const.DATA_SUCCEED);
        } catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
    /*
     * 配置医生基本信息
     * */
    @RequestMapping("insertAskDoctor")
    public AjaxRes insertAskDoctor(AjaxRes ajaxRes, Long userId, YmDoctor ymDoctor){
        try {
           Integer number = askDoctorService.insertYmDoctor(userId,ymDoctor);
            ajaxRes.setSucceed(number,Const.CONFIGURATION_SUCCEED);
        } catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
    /*
     * 问医生-查询医生等级
     * */
    @RequestMapping("queryYmDoctorLevel")
    public AjaxRes queryDoctorLive(AjaxRes ajaxRes){
        try{
            List<YmDoctorLevel> ymDoctorLevelList = askDoctorService.queryYmDoctorLevel();
            ajaxRes.setSucceed(ymDoctorLevelList,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }

    /*
     * 问医生-查询医生咨询类型
     * */
    @RequestMapping("queryYmDouctorConsultType")
    public AjaxRes queryYmDouctorConsultType(AjaxRes ajaxRes){
        try{
            List<YmDouctorConsultType> ymYmDouctorConsultTypeList = askDoctorService.queryYmDouctorConsultType();
            ajaxRes.setSucceed(ymYmDouctorConsultTypeList,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }

    /*
     * 问医生-修改医生信息
     * */
    @RequestMapping("updateYmDouctorInfo")
    public AjaxRes updateYmDouctorInfo(AjaxRes ajaxRes,YmDoctor ymDoctor,Long userId){
        try{
            Integer number  = askDoctorService.updateYmDouctorInfo(userId,ymDoctor);
            ajaxRes.setSucceed(number);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
    /*
     * 问医生-主页显示平台推荐医生
     * */
    @RequestMapping("queryDoctorOrderByQuota")
    public AjaxRes queryDoctorOrderByQuota(AjaxRes ajaxRes){
        try{
            List<YmDoctor> doctorList = askDoctorService.queryYmDoctorOrderByQuota();
            ajaxRes.setSucceed(doctorList,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }

    /*
     * 问医生-主页显示根据登录用户所属区域推荐医生查询
     * */
    @RequestMapping("queryYmDoctorOrderByStationId")
    public AjaxRes queryYmDoctorOrderByStationId(AjaxRes ajaxRes, Long cityAreaId){
        try{
            List<YmDoctor> doctorList = askDoctorService.queryYmDoctorOrderByStationId(cityAreaId);
            ajaxRes.setSucceed(doctorList,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }

    /*
     * 问医生-主页显示查询所有医生
     * */
    @RequestMapping("queryAllYmDoctor")
    public AjaxRes queryAllYmDoctor(AjaxRes ajaxRes){
        try{
            List<YmDoctor> doctorList = askDoctorService.queryAllYmDoctor();
            ajaxRes.setSucceed(doctorList,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
    /**
     * 配置医生在线时间
     *
     * @param  ymDoctorWork
     *
     * @return
     */
    @RequestMapping("insertYmDoctorWork")
    public AjaxRes insertYmDoctorWork(AjaxRes ajaxRes, YmDoctorWork ymDoctorWork){
        try{
            Integer number = ymDoctorWorkService.insertYmDoctorWork(ymDoctorWork);
            ajaxRes.setSucceed(number,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
    /**
     * 删除配置的医生在线时间
     *
     * @param  ymDoctorWork
     *
     * @return
     */
    @RequestMapping("deleteYmDoctorWork")
    public AjaxRes deleteYmDoctorWork(AjaxRes ajaxRes, YmDoctorWork ymDoctorWork){
        try{
            Integer number = ymDoctorWorkService.deleteYmDoctorWork(ymDoctorWork);
            ajaxRes.setSucceed(number,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }

    /**
     * 根据医生ID查询医生在线时间
     *
     * @param  doctorId
     *
     * @return
     */
    @RequestMapping("queryYmDoctorWork")
    public AjaxRes queryYmDoctorWork(AjaxRes ajaxRes, Long doctorId){
        try{
            YmDoctorWork ymDoctorWork = ymDoctorWorkService.queryYmDoctorWork(doctorId);
            ajaxRes.setSucceed(ymDoctorWork,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }

    /**
     * 修改配置的医生在线时间
     *
     * @param  ymDoctorWork
     *
     * @return
     */
    @RequestMapping("updateYmDoctorWork")
    public AjaxRes updateYmDoctorWork(AjaxRes ajaxRes, YmDoctorWork ymDoctorWork){
        try{
            Integer number = ymDoctorWorkService.updateYmDoctorWork(ymDoctorWork);
            ajaxRes.setSucceed(number,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
}
